﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLBH.DATA
{
    public class TonKhoData
    {
        private static QLBHEntities db = new QLBHEntities();
        public string Error { set; get; }

        public List<TON_KHO> LayDanhSachTonKho(DateTime tu_ngay, DateTime den_ngay, string ten_san_pham, string ma_kho_hang)
        {
            db = new QLBHEntities();
            return db.TON_KHO.ToList().Where(p=>p.NGAY_TON_KHO.Date>= tu_ngay.Date &&
                p.NGAY_TON_KHO.Date <= den_ngay.Date &&
                p.SAN_PHAM.TEN_SAN_PHAM.ToLower().Contains(ten_san_pham.ToLower()) && p.MA_KHO_HANG == ma_kho_hang).Select(p => new TON_KHO()
                {
                    BAO_HANH = p.BAO_HANH,
                    DON_GIA_BINH_QUAN = p.DON_GIA_BINH_QUAN,
                    KHO_HANG = new KHO_HANG()
                    {
                        MA_KHO_HANG = p.KHO_HANG.MA_KHO_HANG,
                        TEN_KHO_HANG = p.KHO_HANG.TEN_KHO_HANG
                    },
                    NGAY_TON_KHO = p.NGAY_TON_KHO,
                    NHAP_TRONG_KY = p.NHAP_TRONG_KY,
                    TON_CUOI_KY = p.TON_CUOI_KY,
                    TON_DAU_KY = p.TON_DAU_KY,
                    XUAT_TRONG_KY = p.XUAT_TRONG_KY,
                    SAN_PHAM = new SAN_PHAM()
                    {
                        MA_SAN_PHAM = p.SAN_PHAM.MA_SAN_PHAM,
                        TEN_SAN_PHAM = p.SAN_PHAM.TEN_SAN_PHAM
                    }
                }).ToList().OrderBy(p=>p.SAN_PHAM.TEN_SAN_PHAM).ToList();

        }
    }
}